import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Body from "../components/Body";
import store from "../store/index"

Vue.use(VueRouter)

const routes = [

  {
    path: '/',
    name: 'Home',
    component: Home,
    children:[
      {
        path:"",
        component:Body
      },
      {
        path:"CourseDetail",
        component:()=>import("../components/CourseDetail")
      },
    ]
  },
  {
    path: '/ShoppingCart',
    component: ()=>import("../components/ShoppingCart"),
    meta:{
      islogin:true
    }
  }


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
let getMessage=store.dispatch("getMessage")
router.beforeEach((to,from,next)=>{
  if(to.meta.islogin){
    getMessage.then(()=>{
      if(store.state.logAfter){
        next();
      }else{
        store.commit("changeFT",true)
      }
    })
  }else{
    next()
  }
})



export default router
